package com.future.bantang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.bantang.R;
import com.future.bantang.app.BanTangAPP;
import com.future.bantang.entity.UserRecommendEntity.DataEntity.ListEntity;
import com.future.bantang.view.CircleImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 16-1-20.
 */
public class UserRecommendAdapter extends BaseAdapter<ListEntity> {

    private ImageLoader mImageLoader;


    public UserRecommendAdapter(Context context) {
        super(context);
        mImageLoader= BanTangAPP.getApp().getImageLoader();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_user_recommend_list,null);
            holder=new ViewHolder();
            ViewUtils.inject(holder,convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.setDatas(mList.get(position));
        return convertView;
    }

    private class ViewHolder {
        @ViewInject(R.id.civ_user_recomment_user_img)
        private CircleImageView civUserImg;
        @ViewInject(R.id.tv_user_name_user_recommend)
        private TextView tvUserName;
        @ViewInject(R.id.iv_user_recommend_level)
        private ImageView ivLevel;
        @ViewInject(R.id.tv_data_time_user_recommend)
        private TextView tvDataTime;
        @ViewInject(R.id.iv_pic_user_recommend)
        private ImageView ivPic;
        @ViewInject(R.id.tv_user_desc_user_recommend)
        private TextView tvUserDesc;
        @ViewInject(R.id.iv_product_pic_user_recommend)
        private ImageView ivProductPic;
        @ViewInject(R.id.tv_product_name_user_recommend)
        private TextView tvProductName;
        @ViewInject(R.id.tv_product_price_user_recommend)
        private TextView tvProductPrice;
        @ViewInject(R.id.tv_like_num_user_recommend)
        private TextView tvLikeNum;
        @ViewInject(R.id.iv_my_icon_user_recommend)
        private CircleImageView ivMyIcon;


        public void setDatas(ListEntity entity){
            tvDataTime.setText(entity.getDatestr());
            tvLikeNum.setText(entity.getDynamic().getLikes());
            tvProductName.setText(entity.getProduct().get(0).getTitle());
            tvProductPrice.setText(entity.getProduct().get(0).getPrice());
            tvUserDesc.setText(entity.getContent());
            tvUserName.setText(entity.getAuthor().getUsername());



            mImageLoader.displayImage(entity.getAuthor().getAvatar(), civUserImg);
            String url=entity.getPics().get(0).getUrl();
            url=url.substring(0,url.indexOf('!'));
            mImageLoader.displayImage(url,ivPic);
            mImageLoader.displayImage(entity.getProduct().get(0).getPic(),ivProductPic);


        }

    }

}
